package com.ol.edu.server.service.Authority.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ol.edu.server.entity.Resource;
import com.ol.edu.server.entity.ResourseVo;
import com.ol.edu.server.entity.ResponseResult;
import com.ol.edu.server.mapper.ResourceMapper;
import com.ol.edu.server.service.Authority.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Roger
 * @date 2020/9/9 10:34
 * @description
 */
@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceMapper resourceMapper;
    /*
        资源信息分页&条件查询
     */
    @Override
    public ResponseResult findAllResource(ResourseVo resourseVo) {
        //获取分页数据
        PageHelper.startPage(resourseVo.getCurrentPage(), resourseVo.getPageSize());
        List<Resource> resourceList = resourceMapper.findAllResource(resourseVo);
        PageInfo<Resource> pageInfo = new PageInfo<>(resourceList);
        return new ResponseResult(true, 200, "查询成功", pageInfo);
    }
    /*
        添加 资源信息
     */
    @Override
    public void saveResource(Resource resource) {
        Date date = new Date();
        resource.setCreatedTime(date);
        resource.setUpdatedTime(date);
        resource.setCreatedBy("system");
        resource.setUpdatedBy("system");

        resourceMapper.saveResource(resource);
    }
    /*
         更新资源信息
     */
    @Override
    public void updateResource(Resource resource) {
        resource.setUpdatedTime(new Date());

        resourceMapper.updateResource(resource);
    }
    /*
        删除资源信息
     */
    @Override
    public void deleteResource(Integer id) {
        resourceMapper.deleteResource(id);
    }
}
